package com.kucai.yifaqapp.presenter.activity;

import android.widget.Toast;

import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.ResIdear;
import com.kucai.yifaqapp.model.network.entity.res.ResIdearlists;
import com.kucai.yifaqapp.ui.activity.EditActivity;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/12/9.
 */

public class EditActivityPesenter extends BaseActivityPresenter<EditActivity> {
    public EditActivityPesenter(EditActivity mActivity) {
        super(mActivity);
    }

    /**
     * 试玩登录
     */
    public void putidear(String token, String type, String content) {
        HttpJsonUtils.getHttpApiInstance()
                .putidear(HttpAdress.getuseAdress() + "api/mobile/feedback",token, type, content)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResIdear>() {

                    @Override
                    protected void onCustomNext(ResIdear resLogin) {
                        if (resLogin.code.equals("0") && resLogin.status) {
                            Toast.makeText(mActivity, resLogin.msg, Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(mActivity, resLogin.msg, Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {

                    }
                });
    }

    /**
     * ‘status’: ‘’ //1未回复 2已回复
     * ‘startTime’ : ‘’//开始时间
     * ‘endTime’ : ‘’//结束时间
     */
    public void getidearlists(String token, String status) {
        HttpJsonUtils.getHttpApiInstance()
                .getidearlists(HttpAdress.getuseAdress() + "api/mobile/feedbackMessage",token, status)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResIdearlists>() {

                    @Override
                    protected void onCustomNext(ResIdearlists resIdearlist) {
                        if (resIdearlist.code == 0 && resIdearlist.data != null) {
                            mActivity.getIdear(resIdearlist);
                        }

                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {

                    }
                });
    }
}